
import CommunityNoticeAPI from '../api/communitynotice.js';

export const CommunityNotice={
   state:{
      communitynoticelist:[],
      communitynotice_total_count:0,
      editCommunityNoticeStatus:-1,     //插入状态 0失败  1成功  -1不改变
      communitynoticeinfo:[],
      delCommunityNoticeStatus:-1,       //删除状态
      //筛选条件
      comnotice_c_id:''
   },
   mutations:{
      setCommunityNoticeList(state,list){
          state.communitynoticelist=list;
      },
      setCommunityNoticeTotalCount(state,total_count){
          state.communitynotice_total_count=total_count;
      },
      setEditCommunityNoticeStatus(state,status){
          state.editCommunityNoticeStatus=status;
      },
      setCommunityNoticeInfo(state,info){
          state.communitynoticeinfo=info;
      },
      setDelCommunityNoticeStatus(state,status){
          state.delCommunityNoticeStatus=status;
      },
      setComNoticeCId(state,c_id){
          state.comnotice_c_id=c_id;
      }
   },
   actions:{
      loadCommunityNoticeList(context,data){
          CommunityNoticeAPI.getCommunityNoticeList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCommunityNoticeList',response.data.list);
                  context.commit('setCommunityNoticeTotalCount',response.data.total_count);
              }
          })
      },
      //插入CommunityNotice
      editCommunityNotice(context,data){
          CommunityNoticeAPI.editCommunityNotice(data).then(function(response){
              context.commit('setEditCommunityNoticeStatus',response.data.code);
          })
      },
      //获取详情
      loadCommunityNoticeInfo(context,data){
          CommunityNoticeAPI.getCommunityNoticeInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCommunityNoticeInfo',response.data.info);
              }
          })
      },
      //删除
      delCommunityNotice(context,data){
          CommunityNoticeAPI.delCommunityNotice(data).then(function(response){
                context.commit('setDelCommunityNoticeStatus',response.data.code);
          })
      }
   },
   getters:{
      getCommunityNoticeList:state =>{
         return state.communitynoticelist
      },
      getCommunityNoticeTotalCount: state =>{
         return state.communitynotice_total_count
      },
      getEditCommunityNoticeStatus:state=>{
          return state.editCommunityNoticeStatus;
      },
      getCommunityNoticeInfo:state => {
          return state.communitynoticeinfo;
      },
      getDelCommunityNoticeStatus:state => {
          return state.delCommunityNoticeStatus;
      },
      getComNoticeCId:state => {
          return state.comnotice_c_id;
      }
   }
}
